package models

import "time"

type MemTer struct {
	Id    int       `json:"id"`
	Name  string    `json:"name"`
	Phone string    `json:"phone"`
	Types string    `json:"types"`
	Price float64   `json:"price"`
	Times time.Time `json:"times"`
}

func MysqlList(page int, pageSize int, name string) ([]MemTer, int64, error) {
	var memter []MemTer
	var total int64
	query := DB.Model(&MemTer{})
	if name != "" {
		query = query.Where("name like ?", "%"+name+"%")
	}
	if err = query.Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = query.Order("id desc").Offset((page - 1) * pageSize).Limit(pageSize).Find(&memter).Error; err != nil {
		return nil, 0, err
	}
	return memter, total, nil
}
